#include "signalset.h"
#include "ui_signalset.h"
#include "mainWidget.h"

SignalSet::SignalSet(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::SignalSet)
{
    ui->setupUi(this);

    pWidget = static_cast<Widget*>(parent);
    this->init();

    //返回设置子界面
    connect(ui->Btn_back, &QPushButton::clicked, this, [=](){
        pWidget->backSetPage();
    });

    connect(ui->Btn_InputSet, &QPushButton::clicked, this, [=](){
        ui->stackedWidget->setCurrentIndex(InputSet_id);
        ui->stackedWidget_dialog->setCurrentIndex(InputSetDialog_id);
    });
    this->inputSet();
    connect(ui->Btn_OutputSet, &QPushButton::clicked, this, [=](){
        ui->stackedWidget->setCurrentIndex(OutputSet_id);
        ui->stackedWidget_dialog->setCurrentIndex(OutputSetDialog_id);
    });
    this->outputSet();
}

SignalSet::~SignalSet()
{
    delete ui;
}

void SignalSet::init()
{
    ui->stackedWidget->setCurrentIndex(IOSetSel_id);
    ui->stackedWidget_input->setCurrentIndex(0);
    ui->stackedWidget_output->setCurrentIndex(0);
    ui->stackedWidget_dialog->hide();
}

//输入IO设置界面信号和槽的链接
void SignalSet::inputSet()
{
    connect(ui->Btn_inputPageUp, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_input->setCurrentIndex(0);
    });
    connect(ui->Btn_inputPageDown, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_input->setCurrentIndex(1);
    });
    connect(ui->Btn_X0, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_input->setText("X0");
    });
    connect(ui->Btn_X1, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_input->setText("X1");
    });
    connect(ui->Btn_X2, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_input->setText("X2");
    });
    connect(ui->Btn_X3, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_input->setText("X3");
    });
    connect(ui->Btn_X4, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_input->setText("X4");
    });
    connect(ui->Btn_X5, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_input->setText("X5");
    });
    connect(ui->Btn_X6, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_input->setText("X6");
    });
    connect(ui->Btn_X7, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_input->setText("X7");
    });
    connect(ui->Btn_X8, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_input->setText("X8");
    });
    connect(ui->Btn_X9, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_input->setText("X9");
    });
    connect(ui->Btn_X10, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_input->setText("X10");
    });
    connect(ui->Btn_X11, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_input->setText("X11");
    });
    connect(ui->Btn_X12, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_input->setText("X12");
    });
    connect(ui->Btn_X13, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_input->setText("X13");
    });
    connect(ui->Btn_X14, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_input->setText("X14");
    });
    connect(ui->Btn_X15, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_input->setText("X15");
    });
    connect(ui->Btn_X16, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_input->setText("X16");
    });
    connect(ui->Btn_X17, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_input->setText("X17");
    });
    connect(ui->Btn_X18, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_input->setText("X18");
    });
    connect(ui->Btn_X19, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_input->setText("X19");
    });
    connect(ui->Btn_X20, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_input->setText("X20");
    });
    connect(ui->Btn_X21, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_input->setText("X21");
    });
    connect(ui->Btn_X22, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_input->setText("X22");
    });
    connect(ui->Btn_X23, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_input->setText("X23");
    });
    connect(ui->Btn_X24, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_input->setText("X24");
    });
    connect(ui->Btn_X25, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_input->setText("X25");
    });
    connect(ui->Btn_X26, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_input->setText("X26");
    });
    connect(ui->Btn_X27, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_input->setText("X27");
    });
    connect(ui->Btn_X28, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_input->setText("X28");
    });
    connect(ui->Btn_X29, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_input->setText("X29");
    });
    connect(ui->Btn_inputSetOk, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->hide();
    });
    connect(ui->Btn_inputSetCancel, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->hide();
    });
    connect(ui->Btn_inputBack, &QPushButton::clicked, this, [=](){
        ui->stackedWidget->setCurrentIndex(IOSetSel_id);
    });
}

//输出IO设置界面信号和槽的链接
void SignalSet::outputSet()
{
    connect(ui->Btn_outputPageUp, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_output->setCurrentIndex(0);
    });
    connect(ui->Btn_outputPageDown, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_output->setCurrentIndex(1);
    });
    connect(ui->Btn_Y0, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_output->setText("Y0");
    });
    connect(ui->Btn_Y1, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_output->setText("Y1");
    });
    connect(ui->Btn_Y2, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_output->setText("Y2");
    });
    connect(ui->Btn_Y3, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_output->setText("Y3");
    });
    connect(ui->Btn_Y4, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_output->setText("Y4");
    });
    connect(ui->Btn_Y5, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_output->setText("Y5");
    });
    connect(ui->Btn_Y6, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_output->setText("Y6");
    });
    connect(ui->Btn_Y7, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_output->setText("Y7");
    });
    connect(ui->Btn_Y8, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_output->setText("Y8");
    });
    connect(ui->Btn_Y9, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_output->setText("Y9");
    });
    connect(ui->Btn_Y10, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_output->setText("Y10");
    });
    connect(ui->Btn_Y11, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_output->setText("Y11");
    });
    connect(ui->Btn_Y12, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_output->setText("Y12");
    });
    connect(ui->Btn_Y13, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_output->setText("Y13");
    });
    connect(ui->Btn_Y14, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_output->setText("Y14");
    });
    connect(ui->Btn_Y15, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_output->setText("Y15");
    });
    connect(ui->Btn_Y16, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_output->setText("Y16");
    });
    connect(ui->Btn_Y17, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_output->setText("Y17");
    });
    connect(ui->Btn_Y18, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_output->setText("Y18");
    });
    connect(ui->Btn_Y19, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_output->setText("Y19");
    });
    connect(ui->Btn_Y20, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_output->setText("Y20");
    });
    connect(ui->Btn_Y21, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_output->setText("Y21");
    });
    connect(ui->Btn_Y22, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_output->setText("Y22");
    });
    connect(ui->Btn_Y23, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_output->setText("Y23");
    });
    connect(ui->Btn_Y24, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_output->setText("Y24");
    });
    connect(ui->Btn_Y25, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_output->setText("Y25");
    });
    connect(ui->Btn_Y26, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_output->setText("Y26");
    });
    connect(ui->Btn_Y27, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_output->setText("Y27");
    });
    connect(ui->Btn_RY0, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_output->setText("RY0");
    });
    connect(ui->Btn_RY1, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->show();
        ui->Edit_output->setText("RY1");
    });
    connect(ui->Btn_outputSetOk, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->hide();
    });
    connect(ui->Btn_outputSetCancel, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_dialog->hide();
    });
    connect(ui->Btn_outputBack, &QPushButton::clicked, this, [=](){
        ui->stackedWidget->setCurrentIndex(IOSetSel_id);
    });
}
